<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 CalenderUI();
 link_js(array('jquery.fixedheader','bootstrap-typeahead','jquery.maskedit.min'),'asset/js/');
 ?>
<!--<div class='container'>-->
     <div class="tabbable"> <!-- Only required for left/right tabs -->
	<?=$tab_header;?>
       <div class="tab-content" style=''>
	   <br>
            <div class="tab-pane" id="table1"></div>
            <div class="tab-pane active" id="table2"><?=$this->zetro_auth->allAuth($frm3,'list_karyawan');?><?=$this->zetro_auth->allAuth($list,'list_karyawan');?></div></div>
       </div>
		<input type='hidden' id='row_aktif' value='<?=empty($_GET['ot'])?'n':$_GET['ot'];?>'/>
		<input type='hidden' id='rows' value='<?=base64_decode($this->session->userdata('menus'));?>'/>
    </div>
<!--</div>-->
<?=$modal;?>
<script language='javascript'>
$(document).ready(function(e) {
	$('#bln').html("<?=$bln;?>");
	$('#thn').html("<?=$thn;?>");
	$('#frm4').validationEngine();
	$('#c_id_karyawan').click(function(){ _show_data('1');})
	$('#b_Saved').click(function(){($('#frm4').validationEngine('validate'))?_simpan_data():'';})
	$('#d_Saved').click(function(){ $('#myModal').modal('hide');})
	_get_employee_name();
	_show_data('');
	$('input:checkbox').live('click',function()
	{
		var a=$(this).attr('id').split('_');
		if($(this).is(':checked'))
		{
			jPrompt('Masukan Alasan Lembur nya','Overtime reaason','Alert',function(r)
			{
				if(r)
				{
					$.post('setlembur',{'id':a[1],'reson':r},
					function(result)
					{
						_show_data('1');
					})
				}else{
				$(':checkbox#l_'+a[1]).removeAttr('checked');	
				}
			})
		}else{
			jConfirm('Yakin kelebihan jam ini tidak di anggap lembur','Alert',function(r)
			{
				if(r)
				{
					$.post('settidaklembur',{'id':a[1]},function(result)
					{
						_show_data('1');
						$(':checkbox#l_'+a[1]).removeAttr('checked');	
					})
				}else{
					$(':checkbox#l_'+a[1]).attr('checked',true);
				}
			})
		};
	})

})

function _show_data(tp)
{
		show_indicator2('txt');
		$.post('listabsens',$('#frm1').serialize()+'&ot='+$('#row_aktif').val(),function(result)
		{
			$('#NewList tbody').html(result);
			(tp=='')?
			$('#NewList').fixedHeader({'width':(screen.availWidth-50),'height':(screen.availHeight-370)}):'';
			$('#txt').html('');
			_get_total_perbln();
		})
}
function _simpan_data()
{
	$.post('setabsensi',$('#frm4').serialize(),function(result)
	{
		$('#d_Saved').click();
		_show_data('1');
	})
}
function absen(aksi,tgl,nik,id)
{
	switch(aksi)
	{
		case 'H':
			//$('#frm4 input:text').removeAttr('readonly')
			$('#frm4 textarea').removeClass("validate[required]").attr('placeholder','Keterangan diisi jika terlambat');
			_show_popup(aksi,tgl,nik,id);
		break;
		case 'C':
			//$('#frm4 input:text').attr('readonly','readonly');
			$('#frm4 textarea').addClass("validate[required]").attr({'placeholder':'Keterangan cuti wajib diisi'});
			_show_popup(aksi,tgl,nik,id);
		break;
		case 'A':
			$('#frm4 textarea').addClass("validate[required]").attr({'placeholder':'Di isi dengan tanpa keterangan'});
			//$('#frm4 input:text').attr('readonly','readonly');
			_show_popup(aksi,tgl,nik,id);
		break;	
	}
}

function _show_popup(aksi,tgl,nik,id)
{
	$('#tgl_absen').val(tgl).attr('readonly','readonly');
	$('#jam_masuk').val('08:00').mask("99:99")
	$('#jam_keluar').val('16:00').mask("99:99")
	$('#nik_employee').val(nik);
	$('#id').val(id);
	$('#stat').val(aksi);
	$('#myModal')
		.css({'top':'30%'})
		.modal('show');
}

function _get_total_perbln()
{
	$.post('gettotaljambulan',$('#frm1').serialize(),function(rst){
		var rs=rst.split('|');
		(rs[1]=='00:00:00')?
		$('span#txt').html('Total Jam Kerja : '+ rs[0] ):
		$('span#txt').html('Total Jam Kerja : '+ rs[0] +' &nbsp; Total Jam Lembur :'+rs[1]);
	})
}
function _get_employee_name()
{
	$.post('getemployeename',{'ot':$('#row_aktif').val()},
	function(result){
		$('#id_karyawan').typeahead({source:$.parseJSON(result)});
	})
}

function btn_click(id,aksi)
{
	switch(aksi)
	{
		case 'del':
		jConfirm('Yakin data absen ini akan dihapus?','Ziebar Confirm',function(r)
		{
			if(r)
			{
				$.post('delabsensiharian',{'id':id},function(result)
				{
					$('#c_id_karyawan').click();
				})
			}
			
		})
	}
}
</script>